package com.zbkj.front.controller;

import com.zbkj.common.request.ChangePwdRequest;
import com.zbkj.common.request.SendSmsCodeRequest;
import com.zbkj.common.request.SmsCodeCheckRequest;
import com.zbkj.common.request.user.*;
import com.zbkj.common.response.CommonResult;
import com.zbkj.common.response.user.ClientUserInvoiceResponse;
import com.zbkj.common.response.user.ClientUserLoginResponse;
import com.zbkj.front.service.UserHandleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther:
 * @Date: 2024/7/5 16:36
 * @Description:
 */
@CrossOrigin("*")
@RestController
@RequestMapping("api/front/user")
@Api(tags = "客户端用户服务")
public class UserController {

    @Autowired
    private UserHandleService userHandleService;

    @ApiOperation(value="获取用户信息")
    @GetMapping(value = "/getUser")
    public CommonResult<ClientUserLoginResponse> getUser(HttpServletRequest request) {
        return CommonResult.success(userHandleService.getUser(request));
    }

    @ApiOperation(value="修改密码")
    @PostMapping(value = "/changePwd")
    public CommonResult changePwd(@RequestBody @Validated ChangePwdRequest pwdRequest) {
        userHandleService.changePwd(pwdRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="注册|忘记密码发送短信验证码")
    @PostMapping(value = "/endSmsCode")
    public CommonResult endSmsCode(@RequestBody @Validated SendSmsCodeRequest sendSmsCodeRequest) {
        userHandleService.endSmsCode(sendSmsCodeRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="用户注册")
    @PostMapping(value = "/userRegiste")
    public CommonResult userRegiste(@RequestBody @Validated ClientUserRequest clientUserRequest) {
        userHandleService.userRegiste(clientUserRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="用户忘记密码提交")
    @PostMapping(value = "/forgetPwdSave")
    public CommonResult forgetPwdSave(@RequestBody @Validated UserForgetPwdRequest userForgetPwdRequest) {
        userHandleService.forgetPwdSave(userForgetPwdRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="获取用户发票信息")
    @GetMapping(value = "/getUserInvoice")
    public CommonResult<ClientUserInvoiceResponse> getUserInvoice() {
        return CommonResult.success(userHandleService.getUserInvoice());
    }

    @ApiOperation(value="保存用户发票信息")
    @PostMapping(value = "/userInvoiceSave")
    public CommonResult userInvoiceSave(@RequestBody @Validated ClientUserInvoiceRequest invoiceRequest) {
        userHandleService.userInvoiceSave(invoiceRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="短信验证码检查")
    @PostMapping(value = "/smsCodeCheck")
    public CommonResult smsCodeCheck(@RequestBody @Validated SmsCodeCheckRequest checkRequest) {
        userHandleService.smsCodeCheck(checkRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="用户实名认证")
    @PostMapping(value = "/userAuthVerify")
    public CommonResult userAuthVerify(@RequestBody @Validated UserAuthVerifyRequest authVerifyRequest) {
        userHandleService.userAuthVerifyOpt(authVerifyRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="用户信息修改")
    @PostMapping(value = "/userInfoModify")
    public CommonResult userInfoModify(@RequestBody @Validated ClientUserModifyRequest userModifyRequest) {
        userHandleService.userInfoModify(userModifyRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="反馈意见保存")
    @PostMapping(value = "/feedbackSave")
    public CommonResult feedbackSave(@RequestBody @Validated ClientFeedbackSaveRequest feedbackSaveRequest) {
        userHandleService.feedbackSave(feedbackSaveRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="用户注册")
    @PostMapping(value = "/userRegisteByAccountPwd")
    public CommonResult userRegisteByAccountPwd(@RequestBody @Validated ClientUserRegionRequest clientUserRegionRequest) {
        userHandleService.userRegisteByAccountPwd(clientUserRegionRequest);
        return CommonResult.success();
    }
}
